﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace dayattheraces
{
    public partial class Form1 : Form
    {

        Guy[] GuyArray = new Guy[3];
        Greyhound[] GreyhoundArray = new Greyhound[4];
        Random MyRandomizer = new Random();
        Guy Bettor;

        public Form1()
        {
            InitializeComponent();

            minimumBetLabel.Text = "Minimum Bet: " + betAmount.Minimum + " bucks";

            //Greyhound[] GreyhoundArray = new Greyhound[4];
            GreyhoundArray[0] = new Greyhound() { MyPictureBox = pictureBox1, StartingPosition = pictureBox1.Left, RacetrackLength = racetrackPictureBox.Width - pictureBox1.Width, Randomizer = MyRandomizer };
            GreyhoundArray[1] = new Greyhound() { MyPictureBox = pictureBox2, StartingPosition = pictureBox2.Left, RacetrackLength = racetrackPictureBox.Width - pictureBox2.Width, Randomizer = MyRandomizer };
            GreyhoundArray[2] = new Greyhound() { MyPictureBox = pictureBox3, StartingPosition = pictureBox3.Left, RacetrackLength = racetrackPictureBox.Width - pictureBox3.Width, Randomizer = MyRandomizer };
            GreyhoundArray[3] = new Greyhound() { MyPictureBox = pictureBox4, StartingPosition = pictureBox4.Left, RacetrackLength = racetrackPictureBox.Width - pictureBox4.Width, Randomizer = MyRandomizer };

            //Guy[] GuyArray = new Guy[3];
            GuyArray[0] = new Guy() { Name = "Joe", Cash = 50, MyLabel = joeBetLabel, MyRadioButton = joeRadioButton, MyBet = new Bet() };
            GuyArray[1] = new Guy() { Name = "Bob", Cash = 75, MyLabel = bobBetLabel, MyRadioButton = bobRadioButton, MyBet = new Bet() };
            GuyArray[2] = new Guy() { Name = "Al", Cash = 45, MyLabel = alBetLabel, MyRadioButton = alRadioButton, MyBet = new Bet() };

           

            for (int i = 0; i < GuyArray.Length; i++)
            {
                //MyRadioButton.Text = Name + " has " + Cash + " bucks";
                GuyArray[i].UpdateLabels();
                
            }
        }

        private void raceButton_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < GreyhoundArray.Length; i++)
            {

                if (GreyhoundArray[i].Run())
                {
                    timer1.Stop();
                    MessageBox.Show("Dog # " + (i + 1) + " wins");

                    for (int a = 0; a < GuyArray.Length; a++)
                    {
                        GuyArray[a].Collect((i+1));
                        
                    }

                    for (int j = 0; j < GreyhoundArray.Length; j++)
                    {
                        GreyhoundArray[j].TakeStartingPosition();
                    }                    
                }
            }
        }

        

        private void joeRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (joeRadioButton.Checked)
            {
                nameLabel.Text = GuyArray[0].Name;
                Bettor = GuyArray[0];
                
            }
        }

        private void bobRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (bobRadioButton.Checked)
            {
                nameLabel.Text = GuyArray[1].Name;
                Bettor = GuyArray[1];
            }
        }

        private void alRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (alRadioButton.Checked)
            {
                nameLabel.Text = GuyArray[2].Name;
                Bettor = GuyArray[2];
            }
        }

        private void betButton_Click(object sender, EventArgs e)
        {
            Bettor.PlaceBet((int)betAmount.Value, (int)dogToWin.Value);
            Bettor.UpdateLabels();
        }
    }
}
